package housing.task1.document;

import housing.task1.actor.Renter;
import housing.task1.actor.Worker;
import housing.task1.generator.AutoCompleter.WorkType;

import java.util.ArrayList;
import java.util.GregorianCalendar;

/**
 * Singleton class for creating unique instance of WorkPlan.
 *
 * @author Marshall
 * @version 1.5 22 Oct 2010
 */
public class WorkPlan {

    private ArrayList<Request> requests = new ArrayList<Request>();
    private ArrayList<Worker> workers = new ArrayList<Worker>();
    private ArrayList<Punct> puncts = new ArrayList<WorkPlan.Punct>();

    private static WorkPlan instance = null;

    public static synchronized WorkPlan getInstance() {
        if (instance == null) {
            System.out.println("Creating the WorkPlan");
            instance = new WorkPlan();
        } else {
            // System.err.println("An instance of WorkPlan already exists!");
        }// if-else

        return instance;
    }// WorkPlan getInstance

    public WorkPlan() {

    }// WorkPlan()

    public void update(GregorianCalendar d, Renter s, WorkType wt, Worker brig) {
        puncts.add(new Punct(d, s, wt, brig));
    }// void update()

    @Override
    public String toString() {
        return "WorkPlan [requests=" + requests + ", workers=" + workers
               + ", puncts=" + puncts + "]";
    }


    /**
     * @param requests the requests to set
     */
    public void setRequests(ArrayList<Request> requests) {
        this.requests = requests;
    }// setter

    /**
     * @return the requests
     */
    public ArrayList<Request> getRequests() {
        return requests;
    }// getter

    /**
     * @param workers the workers to set
     */
    public void setWorkers(ArrayList<Worker> workers) {
        this.workers = workers;
    }// setter

    /**
     * @return the workers
     */
    public ArrayList<Worker> getWorkers() {
        return workers;
    }// getter

    /**
     * @return the puncts
     */
    public ArrayList<Punct> getPuncts() {
        return puncts;
    }


    /**
     * Inner class for representing Puncts of the Plan
     *
     * @author Marshall
     */
    public class Punct {

        /**
         * Instance variable for keeping date of work planned
         */
        private GregorianCalendar date;
        private Renter sender;
        private WorkType workType;
        private Worker brigade;

        private Punct(GregorianCalendar d, Renter s, WorkType wt, Worker brig) {
            setDate(d);
            setSender(s);
            setWorkType(wt);
            setBrigade(brig);
        }// constructor Punct()

        @Override
        public String toString() {
            return "Punct [date=" + date + ", sender=" + sender + ", workType="
                   + workType + ", brigade=" + brigade + "]";
        }

        /**
         * @param date the date to set
         */
        public void setDate(GregorianCalendar date) {
            this.date = date;
        }

        /**
         * @return the date
         */
        public GregorianCalendar getDate() {
            return date;
        }

        /**
         * @param sender the sender to set
         */
        public void setSender(Renter sender) {
            this.sender = sender;
        }

        /**
         * @return the sender
         */
        public Renter getSender() {
            return sender;
        }

        /**
         * @param workType the workType to set
         */
        public void setWorkType(WorkType workType) {
            this.workType = workType;
        }

        /**
         * @return the workType
         */
        public WorkType getWorkType() {
            return workType;
        }

        /**
         * @param brigade the brigade to set
         */
        public void setBrigade(Worker brigade) {
            this.brigade = brigade;
        }

        /**
         * @return the brigade
         */
        public Worker getBrigade() {
            return brigade;
        }

    }// class Punct

}// class WorkPlan
